package com.zhiyou.app.shop.website.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.app.shop.common.util.Page;
import com.zhiyou.app.shop.website.dao.IStockInfoDao;
import com.zhiyou.app.shop.website.dao.IStockPoolDao;
import com.zhiyou.app.shop.website.dao.IStockTypeDao;
import com.zhiyou.app.shop.website.dao.IUserStockInfoDao;
import com.zhiyou.app.shop.website.dao.pojo.StockInfo;
import com.zhiyou.app.shop.website.dao.pojo.StockPool;
import com.zhiyou.app.shop.website.dao.pojo.StockType;
import com.zhiyou.app.shop.website.dao.pojo.UserStockInfo;
import com.zhiyou.app.shop.website.service.IStockService;

@Service(value="stockService")
public class StockServiceImpl implements IStockService {
	
	@Autowired
	private IStockInfoDao stockInfoDao;
	@Autowired
	private IStockPoolDao stockPoolDao;
	@Autowired
	private IUserStockInfoDao userStockInfoDao;
	@Autowired
	private IStockTypeDao stockTypeDao;

	public float findPrice() {
		List<StockType> list = stockTypeDao.findByProperty("attr1", "1");
		if(list != null && list.size() > 0){
			return list.get(0).getCurPrice();
		}
		return 0;
	}
	
/*	public BigDecimal getNewPrice() {
		List<StockInfo> list = stockInfoDao.findByNewdate();
		StockInfo stockInfo = new StockInfo();
		if(list != null && list.size() >0){
			stockInfo = list.get(0);
		}
		return stockInfo.getCurrentPrice();
		
	}*/

	public UserStockInfo getLastedStockTrade() {
		List<UserStockInfo> list = stockInfoDao.findLasted();
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}

	public StockPool getStockPool() {
		List<StockPool> list = stockPoolDao.findAll();
		if(list != null && list.size() >0 ){
			return list.get(0);
		}
		return null;
	}

	public void findStockInfo(Page page, UserStockInfo userStockInfo) {
		userStockInfoDao.findByExample(page, userStockInfo, Order.desc("createDate"));
	}

	public StockType findStockType() {
		List<StockType> list = stockTypeDao.findByProperty("attr1", "1");
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	
	
	
	
}
